package mysql

import "gorm.io/gorm"

type Manuscript struct {
	gorm.Model
	Title   string `gorm:"type:varchar(30);not null; comment: 标题"`
	Info    string `gorm:"type:varchar(255);not null; comment: 内容"`
	ClassId int    `gorm:"type:int(11);not null; comment: 分类ID"`
}

func (m *Manuscript) ManAdd(db *gorm.DB) error {
	return db.Debug().Create(&m).Error
}

func (m *Manuscript) FindTitle(db *gorm.DB, title string) error {
	return db.Debug().Where("title = ?", title).Find(&m).Error
}

type Class struct {
	gorm.Model
	Name string `gorm:"type:varchar(30);not null; comment: 分类名称"`
}

func (c *Class) ClassNameAdd(db *gorm.DB, name string) error {
	return db.Debug().Where("name = ?", name).FirstOrCreate(c).Error
}
